//
//  XQPersonalViewController.swift
//  XiaoQiQiaoSwift
//
//  Created by tech-lab on 2016/11/24.
//  Copyright © 2016年 校企桥. All rights reserved.
//

import UIKit

class XQPersonalViewController: XQBaseViewController,UITableViewDataSource,UITableViewDelegate {

    private  var tableView = UITableView()

    private var tableHeaderView = UIView()
    private var icon = UIImageView()
    private var nameLable = UILabel()
    private var phoneLabel = UILabel()
    private var button = UIButton()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.title = "个人"
        // Do any additional setup after loading the view.
        self.navigationItem.leftBarButtonItem = nil

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
    
    private func creatHeadView(){
        tableHeaderView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: SCREEN_WIDTH, height: 80))
        tableHeaderView.backgroundColor = UIColor.lightGray
        
        icon = UIImageView.init(frame: CGRect.zero)
        tableHeaderView .addSubview(icon)
        icon.image = UIImage.init(named: "icon")
        
        nameLable = UILabel.init(frame: CGRect.zero)
        nameLable.textColor = UIColor.white
        nameLable.font = UIFont.systemFont(ofSize: 14)
        nameLable.text = "您还没有登陆"
        tableHeaderView .addSubview(nameLable)
        
        phoneLabel = UILabel.init(frame: CGRect.zero)
        phoneLabel.textColor = UIColor.white
        phoneLabel.font = UIFont.systemFont(ofSize: 14)
        tableHeaderView .addSubview(phoneLabel)
        
        button = UIButton.init(frame: CGRect.zero)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        button.backgroundColor = UIColor.gray
        button .setTitleColor(UIColor.white, for: .normal)
        button .setTitle("请登录>", for: .normal)
        tableHeaderView .addSubview(button)
        
        icon.snp.makeConstraints { (make) in
            make.centerY.equalTo(tableHeaderView.snp.centerY)
            make.left.equalTo(tableHeaderView.snp.left).offset(20)
            make.width.equalTo(60)
            make.height.equalTo(60)
        }
        
        nameLable.snp.makeConstraints { (make) in
            make.left.equalTo(icon.snp.right).offset(10)
            make.bottom.equalTo(icon.snp.centerY)
        }
        
        phoneLabel.snp.makeConstraints { (make) in
            make.top.equalTo(icon.snp.centerY)
            make.left.equalTo(icon.snp.right).offset(10)
        }
        
        button.snp.makeConstraints { (make) in
            make.centerY.equalTo(tableHeaderView.snp.centerY)
            make.right.equalTo(tableHeaderView.snp.right).offset(-5)
//            make.topMargin.equalTo(5)
//            make.bottomMargin.equalTo(5)
//            make.leftMargin.equalTo(5)
//            make.rightMargin.equalTo(5)
        }
        
    }
    
    
    override func setRootView() {
        creatHeadView()
        
        self.tableView = UITableView.init(frame:  CGRect.zero, style: .grouped)
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.showsVerticalScrollIndicator = false
        self.view.addSubview(self.tableView)
        
        tableView.snp.makeConstraints { (make) in
            make.left.equalTo(self.view.snp.left)
            make.right.equalTo(self.view.snp.right)
            make.top.equalTo(self.view.snp.top)
            make.bottom.equalTo(self.view.snp.bottom)
        }
        self.tableView.tableHeaderView = self.tableHeaderView
        self.tableView .register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 4
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 1
        }else if section == 3{
            return 2
        }else{
            return 3
        }
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section == 0 {
            return 0.1
        }else{
            return 10
        }
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
        if cell == nil {
            cell = UITableViewCell.init(style: .value2, reuseIdentifier: "cell")
        }
        
        switch indexPath.section {
        case 0:
            cell?.imageView?.image = UIImage.init(named: "per1")
            cell?.textLabel?.text = "个人星级"
            break
        case 1:
            if indexPath.row == 0 {
                cell?.imageView?.image = UIImage.init(named: "per2")
                cell?.textLabel?.text = "我的简历"
            }else if indexPath.row == 1{
                cell?.imageView?.image = UIImage.init(named: "per3")
                cell?.textLabel?.text = "我的课程"
            }else{
                cell?.imageView?.image = UIImage.init(named: "per4")
                cell?.textLabel?.text = "职位库"
            }
            break
        case 2:
            if indexPath.row == 0 {
                cell?.imageView?.image = UIImage.init(named: "per5")
                cell?.textLabel?.text = "钱包"
            }else if indexPath.row == 1{
                cell?.imageView?.image = UIImage.init(named: "per6")
                cell?.textLabel?.text = "消息"
            }else{
                cell?.imageView?.image = UIImage.init(named: "per7")
                cell?.textLabel?.text = "设置"
            }
            break
        case 3:
            if indexPath.row == 0{
                cell?.imageView?.image = UIImage.init(named: "per8")
                cell?.textLabel?.text = "讲师招募"
            }else{
                cell?.imageView?.image = UIImage.init(named: "per9")
                cell?.textLabel?.text = "加入精英圈"
            }
            break
        default:
            break
        }
        
        
        
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }


}
